import React, { useState } from 'react'
import { Modal, Table } from "antd"
import { useSelector } from "umi"
const { Column } = Table;
export default function index({
    isShowAddModal,
    setIsShowAddModal,
    pushOrUpdateList,
    modalType
}) {
    let { departmentList, departmentDetail } = useSelector(state => state.department);
    const [childList, setChildList] = useState([])
    departmentList = departmentList.filter(item => {
        return !item.parentLists[0] && departmentDetail._id !== item._id;
    });

    // 获取添加的Children
    const selectAddChildern = (e, items) => {
        setChildList(items);

    }

    // 执行添加的操作
    const addChildrenList = () => {
        const sendData = { list: childList, type: modalType };
        pushOrUpdateList(sendData);
        // setChildList([]);
        setIsShowAddModal(false);
    }
    return (
        <Modal
            onOk={addChildrenList}
            title="创建子部门"
            open={isShowAddModal}
            onCancel={() => setIsShowAddModal(false)}>
            <Table pagination={false} dataSource={departmentList} rowKey={el => el._id} rowSelection={{ onChange: selectAddChildern }}>
                <Column title="名称" dataIndex="departmentName"></Column>
            </Table>
        </Modal>
    )
}
